<?php
namespace App\Model;
use App\Repository\Common\ConstTable;
use App\Repository\Sys\Db;
use App\Repository\Sys\JsonRespose;
use App\Repository\Sys\Str;
//合作logo表
class LinkTable{
    use Db;
    static private $table = 'link';
    static public function getLinkList($page,$limit,$title,$status){
    	$offset = ($page - 1) * $limit;
        //拼接sql
        $where = "1=1";
        $parameters = array(
            'limit' => $limit,
            'offset' => $offset
        );
        if ($title) {
            $where .= " AND  d.title LIKE :title ";
            $parameters['title'] = $title;
        }
        if ($status) {
            $where .= " AND d.status = :status ";
            $parameters['status'] = $status;
        } else {
            $where .= " AND d.status>0";
        }
        $sql = "select * from link as d  WHERE {$where} ORDER BY d.sort_top DESC,d.sort DESC,d.id DESC limit  :offset,:limit;";
        //执行sql
        $res = \DB::select($sql, $parameters);
        unset($parameters['limit'], $parameters['offset']);
        $count = \DB::select("select count(*) as c from link as d WHERE {$where}", $parameters)[0]->c;
        $data=[];
        foreach ($res as $v) {
        	$v->status_text=ConstTable::ADMIN_STATUS_NAME[$v->status];
        	$data[] = $v;
        }
        return JsonRespose::jsonArray(1,[
            'count' => $count,
            'limit' => $limit,
            'page' => $page,
            'res' => $data
        ]);
    }
}